package com.yjtravel.u70;

import java.util.Scanner;

/**
 * @author weiqi
 * @version 1.0
 * Create by 2024/7/30 8:58
 */
public class Test {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        InputText it = new InputText();
        SnapshotHolder snapshotHolder = new SnapshotHolder();
        while (scanner.hasNext()) {
            String next = scanner.next();
            if(":list".equals(next)){
                System.out.println(it.getText());
            }else if(":undo".equals(next)){
                //回滚到上一次
                Snapshot snapshot = snapshotHolder.popSnapshot();
                it.restoreSnapshot(snapshot);
                System.out.println(snapshot.getText());
            }else {
                it.append(next);
                snapshotHolder.pushSnapshot(it.createSnapshot());
            }
        }
    }
}
